<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Set_cookie_message</title>
</head>

<body>
<!--Add Favorite START-->
<style>
  .tips-modal { display:none;position: fixed; bottom: 0; left: 0; width: 100%; height: 140px; z-index: 10000;background: url("http://cirmall-public.qiniudn.com/gift201810.png") center bottom no-repeat;background-size: cover;}
  .tips-close-btn { display: inline-block; font-size: 14px; color: #cacaca; position: absolute; top: 65px; right: 10px; width: 20px; height: 20px; cursor: pointer;text-align: center; }
  .tips-close-btn:hover { color: #eee; text-decoration: none }
</style>

<a class="tips-modal" href="http://www.stmcu.org.cn/" onclick="addFavorite();return false;" id="newsTipsModal">
  <span class="tips-close-btn" onclick="closeModal();">X</span>
</a>

<script type="text/javascript">
  // 收藏功能
  function addFavorite() {
    var title = '意法半导体STM32/STM8技术社区 - 提供最新的ST资讯和技术交流';
    var URL = 'http://www.stmcu.org.cn/'; 
    // IE10
    if(document.all) {
      window.external.addFavorite(URL, title);
    } else {
      alert('手动 Ctrl+D 可以收藏我们的网站哦');
    }
  }

  // 设置cookie，同一域名都可获取
  function setCookie(name, value, exdays) {
    var exdays = exdays || 1;
    var d = new Date();
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
    document.cookie = name + "=" + escape(value) + ";path=/;expires=" + d.toGMTString();
  }
  // 读取cookies，判断是否存在设置的name
  function getCookie(name) {
    var name = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i].trim();
      if (c.indexOf(name) == 0) {
        return c.substring(name.length, c.length);
      }
    }
    return "";
  }

  function checkCookie() {
    var user = getCookie("msgCookie");
    var width = window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth;
    if(width >= 1080) {
      if (user != "") {
        msgHide();
      } else {
        msgShow();
      }
    }
  }

  // 关闭时设置cookie
  function closeModal() {
    msgHide();
    setCookie("msgCookie", 'msgCookie', 0.5);
  }
  function msgHide() {
    document.getElementById('newsTipsModal').style.display = 'none';
  }
  function msgShow() {
    document.getElementById('newsTipsModal').style.display = 'block';
  }

  // init
  checkCookie();

</script>
<!--Add Favorite END-->
</body>

</html>